package com.project.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.project.bean.DiseaseBean;
import com.project.dao.DiseaseDao;
import com.project.service.DiseaseService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 病害
 */

@Service
@Transactional
public class DiseaseServiceImpl extends ServiceImpl<DiseaseDao, DiseaseBean> implements DiseaseService {
    @Override
    public IPage<DiseaseBean> findAllDisease(int pageNO, int pageSize) {
        Page<DiseaseBean> page = new Page<>(pageNO, pageSize);
        IPage<DiseaseBean> iPage = this.page(page);
        return iPage;
    }

    @Override
    public void addDisease(DiseaseBean diseaseBean) {
        this.baseMapper.addDisease(diseaseBean);
    }

    @Override
    public DiseaseBean findId(int diseaseId) {
        return this.baseMapper.findId(diseaseId);
    }

    @Override
    public IPage<DiseaseBean> findName(int pageNO, int pageSize, String diseaseName, String diseaseSymptom) {
        Page<DiseaseBean> page = new Page<>(pageNO, pageSize);
        QueryWrapper wrapper = new QueryWrapper();
        if (diseaseName != null && !diseaseName.equals("")) {
            wrapper.like("disease_name", diseaseName);
        }
        if (diseaseSymptom != null && !diseaseSymptom.equals("")) {
            wrapper.like("disease_symptom", diseaseSymptom);
        }
        IPage<DiseaseBean> iPage = this.page(page, wrapper);
        return iPage;
    }
}
